package com.py.credit.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.SysUser;
import com.py.credit.service.BigScreenForBlackAndRedService;
import com.py.credit.service.DoublePublicityService;
import com.py.credit.service.RemoteBaseService;
import com.py.framework.core.helper.HttpServletHelper;

/**
 * 异议处理controller
 */
@RestController
@RequestMapping(value = "/bigScreenForBlackAndRed")
public class BigScreenForBlackAndRedController {
	
	private final static String FRONT_TABLE_ID = "bigScreenForBlackAndRed";

    @Autowired
    private BigScreenForBlackAndRedService bigScreenForBlackAndRedService;

    @Autowired
    private RemoteBaseService remoteBaseService;

    @Value("${absolutepath}")
    private String absolutepath;

    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/tendencyAnalyse.json")
    public RestServiceResult<Map<String,List>> tendencyAnalyse(HttpServletRequest request,String type) {
        RestServiceResult<Map<String,List>> result = new RestServiceResult<Map<String,List>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.tendencyAnalyse(type));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/getPie.json")
    public RestServiceResult<Map> getPie(HttpServletRequest request,String type) {
        RestServiceResult<Map> result = new RestServiceResult<Map>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("DissentInfoController#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.getPie(type));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/countByDept.json")
    public RestServiceResult<List<Object[]>> countByDept(HttpServletRequest request,String type) {
        RestServiceResult<List<Object[]>> result = new RestServiceResult<List<Object[]>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.countByDept(type));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/getIndByZone.json")
    public RestServiceResult<List<Map>> getIndByZone(HttpServletRequest request,String type) {
        RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.getIndByZone(type));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/countByHybm.json")
    public RestServiceResult<List<Map>> countByHybm(HttpServletRequest request,String type,String qybm) {
        RestServiceResult<List<Map>> result = new RestServiceResult<List<Map>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.countByHybm(type,qybm));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    /**
     * 根据部门获取近半年数据
     * @param page
     * @return
     */
    @RequestMapping(value = "/getRecentDataByDept.json")
    public RestServiceResult<Map<String,List<Map>>> getRecentDataByDept(HttpServletRequest request) {
        RestServiceResult<Map<String,List<Map>>> result = new RestServiceResult<Map<String,List<Map>>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.getRecentDataByDept());
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
    
    
    /**
     * 异议修改分页列表
     * @param page
     * @return
     */
    @RequestMapping(value = "/getTopEnterprise.json")
    public RestServiceResult<List<Object[]>> getTopEnterprise(HttpServletRequest request,String type,String qybm) {
        RestServiceResult<List<Object[]>> result = new RestServiceResult<List<Object[]>>();

        RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
        SysUser userInfo = null;
        if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
            userInfo = user.getData();
            if (null == userInfo || userInfo.getId() <= 0) {
                result.setCode(RestServiceResult.CODE_UNKNOW);
                result.setMsg("系统异常，请稍后再试！");
                ExceptionLogger.error("bigScreenForBlackAndRedService#getList", "未获取到当前用户信息！");
                return result;
            }

            result.setData(bigScreenForBlackAndRedService.getTopEnterprise(type,qybm));
            return result;
        } else {
            result.setCode(user.getCode());
            result.setMsg(user.getMsg());
            return result;

        }
    }
}